package cn.tedu.tmall.admin.mall.controller;

import cn.tedu.tmall.admin.mall.pojo.param.MallCategoryAddParam;

import cn.tedu.tmall.admin.mall.service.IMallCategoryService;
import cn.tedu.tmall.common.pojo.vo.MallCategoryTreeVO;
import cn.tedu.tmall.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "商城分类管理")
@RequestMapping("mall/category")
@RestController
public class MallCategoryController {

    @Autowired
    private IMallCategoryService categoryService;

    @ApiOperation("增加类别")
    @PostMapping("add")
    public JsonResult addCategory(MallCategoryAddParam param){
        categoryService.addCategory(param);
        return JsonResult.ok();
    }

    /**
     * 全部加载策略
     * @return
     */
    @ApiOperation("类别树")
    @GetMapping("tree")
    public JsonResult treeCategory(){
        List<MallCategoryTreeVO> tree = categoryService.treeCategory();
        return JsonResult.ok(tree);
    }


    /**
     * 延迟加载策略
     * @return
     */
    @ApiOperation("类别树-顶级类别")
    @GetMapping("tree/top")
    public JsonResult treeTopCategory(){
        List<MallCategoryTreeVO> tree = categoryService.treeTopCategory();
        return JsonResult.ok(tree);
    }

    /**
     * 延迟加载策略
     * @return
     */
    @ApiOperation("类别树-子级类别")
    @GetMapping("tree/children/{parentId}")
    public JsonResult treeChildrenCategory(@PathVariable Long parentId){
        List<MallCategoryTreeVO> tree = categoryService.treeChildrenCategory(parentId);
        return JsonResult.ok(tree);
    }


    /**
     * 启用/禁用,排序  不写了,单表的更新操作
     */


}
